package edu.fim.presentation.controller;

import java.sql.SQLException;

import edu.fim.core.exception.CaloriesThresholdExceededException;
import edu.fim.core.service.ConsumerService;
import edu.fim.core.service.locator.ServiceLocator;
import edu.fim.core.util.BmiCategories;
import edu.fim.presentation.model.bean.Consumer;
import edu.fim.presentation.model.bean.Food;


public class ConsumerController {

	private Consumer currentConsumer;

	public ConsumerController(Consumer currentConsumer) {
		this.currentConsumer = currentConsumer;
	}

	public Consumer getCurrentConsumer() {
		return currentConsumer;
	}

	public void setCurrentConsumer(Consumer currentConsumer) {
		this.currentConsumer = currentConsumer;
	}
	
	public void setCaloriesThreshold(Double newThreshold) throws SQLException {
		ConsumerService consumerService = ServiceLocator.getImplementation(ConsumerService.class);
		consumerService.setCaloriesThreshold(currentConsumer, newThreshold);
	}

	public void registerIngestion(Food food) throws CaloriesThresholdExceededException, SQLException {
		ConsumerService cs = ServiceLocator.getImplementation(ConsumerService.class);
		cs.increaseCalories(currentConsumer, food);
	}

	public BmiCategories determineBmi() {
		ConsumerService cs = ServiceLocator.getImplementation(ConsumerService.class);
		return cs.determineWeightSituation(currentConsumer);
	}
}